<template>
	<view>
		<uni-forms ref="form">
			<uni-forms-item label="" name="post">
				<!-- <view>评论：</view> -->
				<view>等级打分：</view>
				<uni-rate value="0"></uni-rate>
				<view class="one">
				<uni-easyinput type="textarea" v-model="data.title" placeholder="请输入title" />
				</view>
				<view class="one">
				<uni-easyinput type="textarea" v-model="data.content" placeholder="请输入content" />
				</view>
				<view class="one">
			    <uni-easyinput type="text" v-model="data.date" placeholder="请输入日期" />
				</view>
				<view class="one">
				<uni-easyinput type="text" v-model="data.name" placeholder="请输入姓名"></uni-easyinput>
				</view>
			</uni-forms-item>
			<uni-forms-item class="AL">
				<button  type="primary" size="mini" @click="lost" class="AL">取消</button> <br>
				<button  type="primary" size="mini" @click="postMessage" class="AL">发表</button>
			</uni-forms-item>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: {
					"title":"",
					"content": "",
					"date": "",
					"id": 0,
					"name": "",
					"title": ""
				}
			}
		},
		methods: {
			lost(){
				uni.navigateBack();
			},
			postMessage() {
				uni.request({
					url: 'http://localhost:8090/freshmenapp/message/addone',
					method: 'POST',
					data: this.data,
					success: res => {
						console.log(res);
						if (res.data.success) {
							uni.showToast({
								title: '发表成功',
								duration:5000
							});
						} else {
							uni.showToast({
								title: '发表失败',
								icon: "error"
							});
						}
					},
					fail: (err) => {
					    console.error(err);
					    uni.showToast({
					        title: '请求失败',
					        icon: 'error'
					    });
					},
					complete: () => {}
				});
			},

		}
	}
</script>

<style>
.AL{
	display: flex;
	justify-content: center;
}
button{
	display: flex;
	justify-content: center;
}
.one{
	text-align: center;
	margin-top: 20px;
	
}
.AL {
	text-align: center;
    display: flex;
    justify-content: space-between; /* 使按钮均匀分布 */
    margin-top: 20px; /* 给按钮添加一些间距 */
}

</style>